package com.game.layer;

import android.graphics.Canvas;

import com.game.state.BasicDragSacleAbleState;


/**
* @author oven:
* @version 创建时间：2012-11-5 下午2:26:29
* 
*/
public abstract class BasicDragableLayer extends BasicLayer{
	protected boolean holdingTransCanvas=false;
	protected float canvasHoldX;
	protected float canvasHoldY;
	protected float canvasTransX;
	protected float canvasTransY;
	protected float basicScaleValue;
	protected float currentScaleValue = 1;
	protected BasicDragSacleAbleState dragState;
	
	public BasicDragableLayer(BasicDragSacleAbleState state) {
		super(state);
		dragState=state;
	}
	
	@Override
	public void draw(Canvas canvas) {
		canvas.save();
		canvas.scale(currentScaleValue,currentScaleValue);
		canvas.translate(canvasTransX,canvasTransY);
		super.draw(canvas);
		//移动画布
		canvas.restore();
	}
	
	/**
	 * 更新移动数据
	 * @param tranx
	 * @param trany
	 */
	public void updateDragInfo(float tranx,float trany){
		if(isInitIng()||!isShow()||gradualchangIng){//初始化    不显示   动画中   不刷新
			return;
		}
		basicScaleValue=0;
		canvasTransX=canvasTransX-tranx;
		canvasTransY=canvasTransY-trany;
	}
	
	/**
	 * 更新缩放数据
	 * @param value
	 */
	public void updateDragInfo(float value){
		if(isInitIng()||!isShow()||gradualchangIng){//初始化    不显示   动画中   不刷新
			return;
		}
		if(basicScaleValue==0){
			 basicScaleValue = value;
		}
		currentScaleValue=value/basicScaleValue;
	}
	
	@Override
	public void show() {
		super.show();
		dragState.registerDragableLayer(this);
	}
	
	@Override
	public void hide() {
		super.hide();
		dragState.unRegisterDragAbleLayer(this);
	}
}

